<?php
/* @var $this ShiftChangeController */
/* @var $model ShiftChange */


$this->breadcrumbs=array(
	'Management'=>array('/site/management/'),
	'Shift Changes'=>array('/shiftChange/management/'),
	'Viewing',
	$model->idshift_change,
);


if ($model->canApproveDeny($model->day_requested)){
		
	$this->menu=array(
		array('label'=>'Approve Change', 'url'=>'#', 'linkOptions'=>array('submit'=>array('approve','id'=>$model->idshift_change),'confirm'=>'Are you sure you want to APPROVE this Request?')),
		array('label'=>'Deny Change', 'url'=>'#', 'linkOptions'=>array('submit'=>array('deny','id'=>$model->idshift_change),'confirm'=>'Are you sure you want to DENY this Request?')),
		array('label'=>'Back to Shift Changes', 'url'=>array('/shiftChange/management')),
	);
} else {
	$this->menu=array(
		array('label'=>'Deny Change', 'url'=>'#', 'linkOptions'=>array('submit'=>array('deny','id'=>$model->idshift_change),'confirm'=>'Are you sure you want to DENY this Request?')),
		array('label'=>'Back to Shift Changes', 'url'=>array('shiftChange/management')),
	);
}

$cs = Yii::app()->getClientScript();  
$cs->registerScript(
  'radio-type-handler',
  '
	function showHideRoster(){
		
		if(document.getElementById("roster-div").style.display == "block") {
			document.getElementById("roster-div").style.display = "none";
			document.getElementById("roster-button").value = "Show Roster Summary";
		} else {
			document.getElementById("roster-div").style.display = "block";
			document.getElementById("roster-button").value = "Close Roster Summary";
		}
	}

  ',
  CClientScript::POS_END
);

$dateArray = explode('-',$model->day_requested);
$dateObject = new DateTime('NOW');
$dateObject->setTimeZone(new DateTimeZone("America/Costa_Rica"));
$dateObject->setDate($dateArray[0],$dateArray[1],$dateArray[2]);  
?>

<h1>Viewing Shift Change for <?php echo $dateObject->format('l jS, F Y'); ?></h1>
<br>
<center>

<div id="top-view-wrapper">
	<div style="width:350px;float:left;padding-left:200px;">
		<?php $this->widget('zii.widgets.CDetailView', array(
			'data'=>$model,
			'attributes'=>array(
				//'idshift_change',
				array(
					'name'=>'Requestor',
					'value'=>$model->requestingUser_relation->fullname),	
				array(
					'name'=>'Requestor\'s Shift',
					'value'=>($model->current_shift != null)? $model->getCurrentShift() : null),		
				array(
					'name'=>'Requested Shift',
					'value'=>$model->requestedShift_relation->name),			
				array(
					'name'=>'Target Q-Shift',
					'value'=>$model->requestedQshift_relation->name),	
				'day_requested',
				array(
					'name'=>'Status',
					'value'=>$model->getStatus($model->request_status)),	
				array(
					'name'=>'Target User',
					'value'=>$model->getTargetUserFullName()),	
				'comments',
				array('label'=>'', 
						'type'=>'raw', 
						'value'=>CHtml::ajaxLink ("Edit Comments",
								  CController::createUrl('shiftChange/ajaxEditComments', array('id'=>$model->idshift_change,'comments'=>$model->comments)),
								  array('update' => '#commentsEdit')
								  )),
			),
		)); ?>
		
		<div id="commentsEdit" style="margin-left:-60px;"></div>
		
	</div>
		
	<div id="membersViewer" style="float:left;width:100px;padding-left:40px"></div>
</div>

</center>
<p><b>

<div style="clear:both;">
	<center>
	<?php echo CHtml::button('Show Roster Summary', array('id'=>'roster-button','onclick'=>'showHideRoster();')); ?>
	</center>
</div>
</b></p>


<div id="roster-div" style="display:none;clear:both;">


<?php $this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'schedule-grid',
	'dataProvider'=>Schedule::getTeamScheduleDateStats($model->team_id, $model->day_requested),
	'enableSorting' => false,
	'columns'=>array(
		/*
		array(
			'name'=>'shift_name',
			'header'=>'Shift',
			'htmlOptions' => array(
								'style' => 'width:50px; text-align:center;',
							 ),
		),		
		array(
			'name'=>'shift_start_time',
			'header'=>'Start Time',
			'htmlOptions' => array(
								'style' => 'width:30px; text-align:center;',
							 ),
		),						
		array(
			'name'=>'shift_end_time',
			'header'=>'End Time',
			'htmlOptions' => array(
								'style' => 'width:30px; text-align:center;',
							 ),
		),	*/	
		array(
			'name'=>'qshift_name',
			'header'=>'Q-Shift',
			'htmlOptions' => array(
								'style' => 'width:50px; text-align:center;',
							 ),
		),		
		array(
			'name'=>'qshift_start_time',
			'header'=>'Start Time',
			'htmlOptions' => array(
								'style' => 'width:30px; text-align:center;',
							 ),
		),						
		array(
			'name'=>'qshift_end_time',
			'header'=>'End Time',
			'htmlOptions' => array(
								'style' => 'width:30px; text-align:center;',
							 ),
		),	/*								
		array(
			'name'=>'qshift_availability',
			'header'=>'Is Active?',
			'htmlOptions' => array(
								'style' => 'width:50px; text-align:center;',
							 ),
		), */
		array(
			'name'=>'total',
			'header'=>'Total Users',
			'htmlOptions' => array(
								'style' => 'width:50px; text-align:center;',
							 ),
		),	
		array(
			'name'  => 'Members',
			//'value' => 'CHtml::link($data[\'username\'],Yii::app()->createUrl("user/view",array("id"=> $data[\'iduser\'])))',
			'type'  => 'raw',
			'value'=>'CHtml::ajaxLink ("View",
					  Yii::app()->createUrl("shiftChange/ajaxMembersView",array("members"=> $data[\'members\'])),
					  array(\'update\' => \'#membersViewer\')
					  )',
			'htmlOptions' => array(
								'style' => 'width:40px; text-align:center;',
								'title'=>'View Members',
							 ),									  
		),

	),
)); ?>


<center>
<?php echo CHtml::button('Close Roster Summary', array('id'=>'roster-button2','onclick'=>'showHideRoster();')); ?>
</center>

</div>
